package cn.cubic.sys.modular.order.controller;

import cn.cubic.core.annotion.BusinessLog;
import cn.cubic.core.enums.LogAnnotionOpTypeEnum;
import cn.cubic.core.pojo.response.ResponseData;
import cn.cubic.core.pojo.response.SuccessResponseData;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import cn.cubic.sys.modular.order.service.OrderService;
import cn.cubic.sys.modular.order.model.param.OrderParam;

import javax.annotation.Resource;

/**
 * 订单信息表 控制器
 */
@RestController
public class OrderController {

    @Resource
    private OrderService orderService;

    /**
     * 分页查询订单信息表
     */
    @GetMapping("/order/page")
    @BusinessLog(title = "订单信息表_分页查询", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData page(OrderParam orderParam) {
        return new SuccessResponseData(orderService.page(orderParam));
    }

    /**
     * 获取全部订单信息表
     */
    @GetMapping("/order/list")
    @BusinessLog(title = "订单信息表_查询所有", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData list(OrderParam orderParam) {
        return new SuccessResponseData(orderService.list(orderParam));
    }

    /**
     * 查看详情订单信息表
     */
    @GetMapping("/order/detail")
    @BusinessLog(title = "订单信息表_查看详情", opType = LogAnnotionOpTypeEnum.DETAIL)
    public ResponseData detail(@Validated(OrderParam.detail.class) OrderParam orderParam) {
        return new SuccessResponseData(orderService.detail(orderParam));
    }

    /**
     * 添加订单信息表
     */
    @PostMapping("/order/add")
    @BusinessLog(title = "订单信息表_增加", opType = LogAnnotionOpTypeEnum.ADD)
    public ResponseData add(@RequestBody @Validated(OrderParam.add.class) OrderParam orderParam) {
        orderService.add(orderParam);
        return new SuccessResponseData();
    }

    /**
     * 删除订单信息表
     */
    @PostMapping("/order/delete")
    @BusinessLog(title = "订单信息表_删除", opType = LogAnnotionOpTypeEnum.DELETE)
    public ResponseData delete(@RequestBody @Validated(OrderParam.delete.class) OrderParam orderParam) {
        orderService.delete(orderParam);
        return new SuccessResponseData();
    }

    /**
     * 编辑订单信息表
     */
    @PostMapping("/order/edit")
    @BusinessLog(title = "订单信息表_编辑", opType = LogAnnotionOpTypeEnum.EDIT)
    public ResponseData edit(@RequestBody @Validated(OrderParam.edit.class) OrderParam orderParam) {
        orderService.edit(orderParam);
        return new SuccessResponseData();
    }


}
